
import Modal from './Modal';

class ModInput {
    constructor() {
      this.$input_data = null;
      this.onOk = null;

      this.show = this.show.bind(this);        //将show的事件绑定到父级元素，从而获取里面的数据（跳出函数限制）
      this.bindOk = this.bindOk.bind(this);
      this.close = this.close.bind(this);
    }

    bindOk(fn) {
      this.onOk = fn;
    }

    close() {
      Modal.hide();
      this.onOk = null;
    }

    show({title, onReady}) {
		const _this = this;
        const tpl = `
          <div class="found">
            <input type="text" class="found_ip" value="" />
          </div>
        `;

        Modal.show2(title, tpl, {

            onReady: function($c) {
              onReady && onReady();
            },
            onOk: function($c) {
              if (_this.onOk) {
                _this.onOk($('div.revise input.revise_inp').val());
              }
            },
            onCancel: function($c) {
              if (_this.onOk) {
                _this.onOk = null;
              }
            },
            btnText: `下一步`
        });
    }
}

export default new ModInput();
